package cn.schoolwow.workflow.test.module.initial;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.quickflow.listener.SingleFlowListener;
import cn.schoolwow.workflow.QuickWorkFlow;
import cn.schoolwow.workflow.entity.WorkFlowInstance;

public class QuickWorkFlowTestSingleFlowHandler implements SingleFlowListener {

    @Override
    public void beforeExecuteFlow(BusinessFlow flow, FlowContext flowContext) throws Exception {
        System.out.println("测试用例开始运行["+flowContext.getCurrentFlowName()+"]");
    }

    @Override
    public void afterExecuteFlow(BusinessFlow flow, FlowContext flowContext) throws Exception {
        System.out.println("测试用例执行完毕["+flowContext.getCurrentFlowName()+"]");

        if(flowContext.containInstanceKey(WorkFlowInstance.class)){
            WorkFlowInstance workFlowInstance = flowContext.checkInstanceData(WorkFlowInstance.class);
            QuickWorkFlow quickWorkFlow = flowContext.checkInstanceData(QuickWorkFlow.class);

            quickWorkFlow.deleteWorkFlowInstance(workFlowInstance.getId());
        }
    }

    @Override
    public String name() {
        return "全局处理器";
    }
}
